package com.wd.tech.adapter.News;

import android.content.Context;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.wd.tech.R;
import com.wd.tech.bean.News_Details_Bean;

import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * date:2020/7/2
 * author:王成虎(13671)
 * month:七月
 * function:资讯详情页
 */
public class NewsDetailsAdapter extends RecyclerView.Adapter<NewsDetailsAdapter.NewsDetailsHolder> {



    private Context context;
    private List<News_Details_Bean.ResultBean> list;

    public NewsDetailsAdapter(Context context, List<News_Details_Bean.ResultBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public NewsDetailsHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.news_details_layout, parent, false);
        return new NewsDetailsHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull NewsDetailsHolder holder, int position) {


        holder.DetilsTitle.setText(list.get(position).getTitle());
        Date date = new Date(list.get(position).getReleaseTime());
        int year = date.getYear();
        int month = date.getMonth();
        int day = date.getDay();
        int hours = date.getHours();
        int minutes = date.getMinutes();
        holder.DetilsTime.setText(year + "-" + month + "-" + day + "      " + hours + ":" + minutes);
        holder.DeilsSource.setText(list.get(position).getSource());
        /*Glide.with(context)
                .load(list.get(position).getThumbnail())
                .circleCrop()
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(20)))
                .into(holder.DetailsImage);*/
        holder.DetailsImage.setImageURI(list.get(position).getThumbnail());
        String content = list.get(position).getContent();
        holder.DetailsContent.setText(Html.fromHtml(content));//这是显示段落文本的,通过解析html
        holder.DetailsContent.setMovementMethod(ScrollingMovementMethod.getInstance());//段落文本的话要加这个
        //推荐
        holder.DetailsTjImage.setImageURI(list.get(position).getInformationList().get(position).getThumbnail());
        holder.DetailsTjJs.setText(list.get(position).getInformationList().get(position).getTitle());
        holder.DetailsPlate.setText(list.get(position).getPlate().get(position).getName());
    }



    @Override
    public int getItemCount() {
        return list.size();
    }


    public class NewsDetailsHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.Details_plate)
        TextView DetailsPlate;
        @BindView(R.id.Details_tj_image)
        SimpleDraweeView DetailsTjImage;
        @BindView(R.id.Details_tj_js)
        TextView DetailsTjJs;
        @BindView(R.id.Details_Content)
        TextView DetailsContent;
        @BindView(R.id.Details_Image)
        SimpleDraweeView DetailsImage;
        @BindView(R.id.Detils_Title)
        TextView DetilsTitle;
        @BindView(R.id.Detils_Time)
        TextView DetilsTime;
        @BindView(R.id.Deils_Source)
        TextView DeilsSource;

        public NewsDetailsHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
